class Solution(object):

    def shortestToChar(self, S, C):
        """
        :type S: str
        :type C: str
        :rtype: List[int]
        """
        distances = list()
        pos = S.find(C)
        for i in range(1, pos + 1):
            distances.append(pos - i)
        last = pos
        while True:
            pos = S.find(C,last+1)
            if pos is -1:
                for i in range(last + 1, len(S)):
                    distances.append(i - last)
                break
            else:
                for i in range(last+1 , pos+1):
                    distances.append(min(abs(i- last) , abs(i-pos)))
                last = pos
        return distances


s = Solution()
s.shortestToChar("iloveleetcode", 'e')
